classdef Accelerometer 
    
    properties(SetAccess = 'private', GetAccess = 'public')
        port;
    end
    
    methods
        function obj = Accelerometer(comPortNumber)
            obj.port = serial(['COM', num2str(comPortNumber)]);
            fopen(obj.port);
            set(obj.port, 'Timeout', 1); %Set timeout of fread
        end
        
        function xMag = getX(obj)
            fwrite(obj.port, 0);
            pause(0.060);
            xMag = fread(obj.port, 1);
        end

        function yMag = getY(obj)
            fwrite(obj.port, 1);
            pause(0.060);
            yMag = fread(obj.port, 1);
        end

        function zMag = getZ(obj)
            fwrite(obj.port, 2);
            pause(0.060);
            zMag = fread(obj.port, 1);
        end
    end
end

% TODO
% Scale the magnitudes of the inputs from acceloermeter
% check if A0 = x mag, A1 = y mag, etc.
% check number of bytes that get returned